package com.haochang.chunkvod.model.order;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.haochang.chunkvod.tools.vod.goods.ShoppingCartManager;

import android.text.TextUtils;

/**
 *@author qintao
 *created at 2016/6/27 16:07
 * 活动详情info
 */

public class ActiveInfo implements Serializable
{
	private String cn_name;
	private String goods_id;
	private int price;
	private int quantity;
	private String taste_types;
	private String unit;
	private String weight;
	private String combos;
	private int orderNum;
	private List<FoodInfo> foodList;
	private String flavor;
	private String standard;
	private String standard_types;

	public String getCn_name()
	{
		return cn_name;
	}

	public void setCn_name(String cn_name)
	{
		this.cn_name = cn_name;
	}

	public String getGoods_id()
	{
		return goods_id;
	}

	public void setGoods_id(String goods_id)
	{
		this.goods_id = goods_id;
	}

	public int getPrice()
	{
		return price;
	}

	public void setPrice(int price)
	{
		this.price = price;
	}

	public int getQuantity()
	{
		return quantity;
	}

	public void setQuantity(int quantity)
	{
		this.quantity = quantity;
	}

	public String getTaste_types()
	{
		return taste_types;
	}

	public void setTaste_types(String taste_types)
	{
		this.taste_types = taste_types;
	}

	public String getUnit()
	{
		return unit;
	}

	public void setUnit(String unit)
	{
		this.unit = unit;
	}

	public String getWeight()
	{
		return weight;
	}

	public void setWeight(String weight)
	{
		this.weight = weight;
	}

	public String getCombos()
	{
		return combos;
	}

	public void setCombos(String combos)
	{
		this.combos = combos;
	}

	public int getOrderNum()
	{
		return orderNum;
	}

	public void setOrderNum(int orderNum)
	{
		this.orderNum = orderNum;
	}

	public List<FoodInfo> getFoodList()
	{
		return foodList;
	}

	public void setFoodList(List<FoodInfo> foodList)
	{
		this.foodList = foodList;
	}

	public String getFlavor()
	{
		return flavor;
	}

	public void setFlavor(String flavor)
	{
		this.flavor = flavor;
	}

	public String getStandard()
	{
		return standard;
	}

	public void setStandard(String standard)
	{
		this.standard = standard;
	}

	public String getStandard_types()
	{
		return standard_types;
	}

	public void setStandard_types(String standard_types)
	{
		this.standard_types = standard_types;
	}

	public ActiveInfo(JSONObject jsonObject)
	{
		if (jsonObject != null)
		{
			this.cn_name = jsonObject.optString("cn_name");
			this.goods_id = jsonObject.optString("goods_id");
			int disPrice = jsonObject.optInt("discount_price");
			if (disPrice > 0)
				this.price = disPrice;//优惠价
			else
				this.price = jsonObject.optInt("branch_price");//门店价
			this.quantity = jsonObject.optInt("quantity");
			this.orderNum = jsonObject.has("default_quantity") ? jsonObject.optInt("default_quantity") : jsonObject.optInt("quantity");
			JSONArray taste_types = jsonObject.optJSONArray("taste_types");
			this.taste_types = (taste_types != null && taste_types.length() > 0 ? taste_types.toString() : "");
			JSONArray standard_types = jsonObject.optJSONArray("standard_type");
			this.standard_types = (standard_types != null && standard_types.length() > 0 ? standard_types.toString() : "");
			this.standard = (standard_types != null && standard_types.length() > 0 && ShoppingCartManager.isSelectStandard(standard_types.toString())
					? ShoppingCartManager.getStandardDetail(standard_types.toString()) : "");
			this.unit = jsonObject.optString("unit");
			JSONArray combosArray = jsonObject.optJSONArray("combos");
			this.combos = combosArray != null && combosArray.length() > 0 ? combosArray.toString() : "";
			List<FoodInfo> foodInfoList = new ArrayList<FoodInfo>();
			try
			{
				JSONArray array = TextUtils.isEmpty(this.getCombos()) ? null : new JSONArray(this.getCombos());
				if (array != null && array.length() > 0)
					for (int j = 0; j < array.length(); j++)
					{
						FoodInfo info = new FoodInfo(array.getJSONObject(j));
						foodInfoList.add(info);
					}
			} catch (JSONException e)
			{
				e.printStackTrace();
			}
			this.foodList = new ArrayList<FoodInfo>();
			this.foodList.addAll(foodInfoList);
		}
	}
}
